package com.blueheart.vcard;

import ezvcard.Ezvcard;
import ezvcard.VCard;
import ezvcard.VCardVersion;
import ezvcard.property.Categories;
import ezvcard.property.StructuredName;

import java.io.IOException;

public class Hello {

    public static void main(String[] args) throws IOException {
        String str =
                "BEGIN:VCARD\r\n" +
                        "VERSION:4.0\r\n" +
                        "N:Doe;Jonathan;;Mr;\r\n" +
                        "FN:John Doe\r\n" +
                        "END:VCARD\r\n";
        //parse the first vCard from the data stream
        VCard vcard = Ezvcard.parse(str).first();

//or parse all vCards from the data stream
//List<VCard> vcards = Ezvcard.parse(str).all();

        String fullName = vcard.getFormattedName().getValue();
        String lastName = vcard.getStructuredName().getFamily();
        System.out.println(fullName + " " + lastName);
        System.out.println("================================");

        VCard vcard1 = new VCard();

        StructuredName n = new StructuredName();
        n.setGroup("AGroup");
        n.setFamily("Doe");
        n.setGiven("Jonathan");
        n.getPrefixes().add("Mr");
        vcard1.setStructuredName(n);
        vcard1.setFormattedName("John Doe");
        vcard1.addEmail("aaaa@qq.com");
        vcard1.addTelephoneNumber("13766668888");
        //vcard1.addCategories(new Categories("abcde"));

        Ezvcard.write(vcard1).version(VCardVersion.V4_0).go(System.out);
    }

}
